﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace KnockKnock
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    
    public class KnockKnock : IKnockKnock
    {
        #region public Functions

        public void FibonacciNumber(long number, out long result)
        {

            try
            {
                result = GetFibonacci(number);
            }
            catch (Exception ex)
            {
                //return -1 to represent error
                result = -1;
            }
        }

        public string ReverseWords(string s)
        {
            char[] str = s.ToCharArray();
            Array.Reverse(str);
            return new string(str);
        }

        public void WhatShapeIsThis(int a, int b, int c, out TriangleType result)
        {
            if (a > 0 && b > 0 && c > 0)
            {
                //check if it is a triangle
                if ((a + b > c) && (a + c > b) && (b + c > a))
                {
                    //check if all sides are equal
                    if (a == b && b == c) result = TriangleType.Equilateral;
                    //check if at least 2 sides are equal
                    else if(a == b || b == c || c == a) result = TriangleType.Isosceles;
                    else result = TriangleType.Scalene;
                    return;
                }
            }
            //not a triangle
            result = TriangleType.Error;


        }

        public string WhatIsYourToken()
        {
            return "21842426-fe31-4d49-a3cb-2152141b7334";
        }

        #endregion

        #region private Functions

        private long GetFibonacci(long number)
        {
            //negative number, return error
            if (number < 0) return -1;
            //numbers equal zero and one have the same fibbunaci
            if (number == 0) return 0;
            if (number == 1) return 1;
            //recurssive
            return GetFibonacci(number - 1) + GetFibonacci(number - 2);
        }

        #endregion
    }
}
